use std::time::Duration;
use axum::Router;
use com::axum::{ cors, not_found };
use tower_http::{timeout::TimeoutLayer, trace::TraceLayer};

mod sys;
pub mod upload;
mod _db;
mod ws;
mod sse;
pub fn router() -> Router {
    Router::new()
    .nest("/api/sys", sys::routes())
    .merge(_db::routes())
    .merge(ws::router())
    .merge(sse::router())
    .nest_service("/upload", tower_http::services::ServeDir::new("upload"))
    .fallback(not_found::index)
    .layer(cors::index())
    // 超时设置，10 秒后关闭连接
    .layer((
        TraceLayer::new_for_http(),
        TimeoutLayer::new(Duration::from_secs(10)),
    ))
    // .layer(com::axum::trace::index())
}